package com.wsc.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wsc.entity.Membership;
import com.wsc.service.MembershipService;

@RestController
@RequestMapping("membership")
@CrossOrigin(origins = "*", maxAge = 3600) // 前后端分离 实现跨域访问
public class MembershipController {
	@Autowired
	private MembershipService ms;

	// 获取所有
	@RequestMapping("getAll")
	// department specialty degree
	public Map<String, Object> getAll(String department, String specialty, String degree, Integer page, Integer limit) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("department", department);
		params.put("specialty", specialty);
		params.put("degree", degree);
		limit = limit == null ? 10 : limit;
		page = page == null ? 0 : page - 1;
		params.put("limit", limit);
		params.put("page", page);
		return ms.getAll(params);
	}

	@RequestMapping("add")
	public Integer add(Membership mship) {
		return ms.add(mship);
	}
	@RequestMapping("delete")
	public Integer delete(Integer id) {
		return ms.delete(id);
	}
	@RequestMapping("update")
	public Integer update(Membership mship) {
		return ms.update(mship);
	}
}
